#include"comm.h"

int main()
{
  key_t k = ftok(PATHNAME, PROJ_ID);
  if(k < 0){
    perror("ftok error");
    return 1;
  }
  printf("key :%d\n", k);

  //int shmid = shmget(k, SIZE, 0);// 
  int shmid = shmget(k, SIZE, IPC_CREAT);//有 创建 ， 没有 获取 
  if(shmid < 0){
    perror("shmget");
    return 2;
  }
  printf("shmid:%d\n", shmid);

  //sleep(10);
  //void *str = (char*)shmat(shmid, NULL, 0);
  char *str = (char*)shmat(shmid, NULL, 0);
  //sleep(5);
  int i = 0;
  while(1){
    str[i] = 'A' + i;
    sleep(1);
    i++;
    //printf("client###: %s\n",str[i]);
    str[i] = '\0';
  }
  
  shmdt(str);
  //sleep(5);
  // shmctl(shmid,IPC_RMID,NULL);
  //sleep(10);

  return 0;
}
